// gcc -ggdb notify-c.c -o notify-c `pkg-config dbus-glib-1 glib-2.0 --cflags --libs`
#include <glib.h>
#include <glib-object.h>
#include <dbus/dbus-glib.h>

#define NOTIFY_DBUS_NAME           "org.freedesktop.Notifications"
#define NOTIFY_DBUS_CORE_INTERFACE "org.freedesktop.Notifications"
#define NOTIFY_DBUS_CORE_OBJECT    "/org/freedesktop/Notifications"

int
main (int argc, char **argv)
{
    DBusGConnection *connection;
    DBusGProxy *proxy;
    GError *error;
    guint ret_id;

    g_type_init ();

    error = NULL;
    connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
    if (connection == NULL) {
        g_printerr ("Failed to open connection to bus: %s\n", error->message);
        g_error_free (error);

        return 1;
    }

    proxy = dbus_g_proxy_new_for_name (connection,
                                       NOTIFY_DBUS_NAME,
                                       NOTIFY_DBUS_CORE_OBJECT,
                                       NOTIFY_DBUS_CORE_INTERFACE);

    error = NULL;
    if (!dbus_g_proxy_call (proxy, "Notify", &error,
                            G_TYPE_STRING, "notify-c",
                            G_TYPE_UINT, 0,
                            G_TYPE_STRING, "/usr/share/icons/Tango/scalable/devices/harddrive.svg",
                            G_TYPE_STRING, "Harddisk em Chamas!",
                            G_TYPE_STRING, "Parece que seu hardisk queimou de vez...",
                            G_TYPE_STRV, NULL,
                            dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE), NULL,
                            G_TYPE_INT, 4000,
                            G_TYPE_INVALID,
                            G_TYPE_UINT, &ret_id,
                            G_TYPE_INVALID))
    {
        if (error->domain == DBUS_GERROR && error->code == DBUS_GERROR_REMOTE_EXCEPTION)
            g_printerr ("Caught remote method exception %s: %s",
                dbus_g_error_get_name (error),
                error->message);
        else
            g_printerr ("Error: %s\n", error->message);

        g_error_free (error);

        return 1;
    }

    g_object_unref (proxy);

    g_print("return id: %d\n", ret_id);

    return 0;
}


